﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace CryptLib;

public class KeyHelper
{
    public static string GenerateRandomIV(int length)
    {
        // 生成一个16字节的随机字节数组
        byte[] randomBytes = new byte[length];
        var rng = new Random();

        rng.NextBytes(randomBytes);

        // 将字节数组转换为16进制字符串
        StringBuilder hexString = new StringBuilder(length * 2);
        foreach (byte b in randomBytes)
        {
            hexString.AppendFormat("{0:X2}", b);
        }
        return hexString.ToString();
    }
}
